
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

class MyPanel extends JPanel implements KeyListener,MouseListener {
	final static int radius = 40;
	boolean bool=false;
	int x,y,prevx,prevy,nextx,nexty,randx,randy;
	class Circle implements Runnable{
		int i,j;
		public void run() {
		
		}
		
	}
	
	Runnable r = new Circle();
	Thread circle = new Thread(r);
	
	public void paint(Graphics g){
	super.paint(g);
	if(bool){
		g.setColor(Color.RED);
	g.fillOval(x-radius/2, y-radius/2, radius, radius);
	
	}
}
	
	
@Override
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
	//System.out.println(arg0.getKeyCode());
	if((arg0.getKeyCode()==83)||(arg0.getKeyCode()==127)){
		bool=false;
		circle.stop();
	}
	}

	@Override
	public void keyReleased(KeyEvent ev) {
		// TODO Auto-generated method stub
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		if(circle.isAlive()){
			circle.stop();
		}
		x=arg0.getX();
		y=arg0.getY();
		bool=true;
		randx=(int)Math.random();
		randy=(int)Math.random();
		repaint();
	
		circle.start();
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
	
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
		
	}

	@Override
	public void mouseReleased(MouseEvent arg1) {
		// TODO Auto-generated method stub
		
	}

	
}
